package com.nf.health.app.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.nf.health.app.R;
import com.nf.health.app.models.Subject;
import com.nf.health.app.utils.ImageLoaderUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * 确认回答的所有题目
 * @author jiax
 *
 */
public class MySubjectAdapter extends BaseAdapter {
	List<Subject> subjects = new ArrayList<Subject>();
	public MySubjectAdapter(List<Subject> subjects) {
		//去除没有实例化Map的对象
		for (int i = 0; i < subjects.size(); i++) {
			if(subjects.get(i).getMap() != null){
				this.subjects.add(subjects.get(i));
			}
		}
	}
	@Override
	public int getCount() {
		return subjects==null?0:subjects.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Subject subject = subjects.get(position);
		ViewHolder holder = ViewHolder.get(parent, convertView, R.layout.item_subject, position);
		ImageView iv_title = holder.getView(R.id.iv_title);
		ImageLoaderUtils.getinstance(parent.getContext()).getImage(iv_title, subject.getImg());
		
		holder.setText(R.id.tv_title_name, subject.getName());
		StringBuilder sb = new StringBuilder();
		for(Map.Entry<String, String> entry : subject.getMap().entrySet()){
			sb.append(entry.getValue());
			sb.append("\r\n");
		}
		holder.setText(R.id.tv_subject_content, sb.toString());
		return holder.getConvertView();
	}

}
